import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @classname 地图选择界面
 * @Author 姬如千泷
 * @Date 2021/5/20  10:48
 * @Version 1.0
 */
public class MyChoose extends JFrame{
    MyChoose myChoose =this;
    int num=10;//倒计时显示
    JLabel jLabel;
    Timer timer;//倒计时线程
    public MyChoose(){
        this.setBounds(400,100,1200,900);
        this.setResizable(false);
        this.setLayout(null);
        this.setTitle("Linの大冒险");
        JLabel label = new JLabel(DateCenter.choose);
        MyButton myButton = new MyButton(600,225,300,200,DateCenter.map);
        JLabel label2 = new JLabel("至暗森林深处");
        label.setBounds(0,-50,1200,900);
        myButton.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(DateCenter.mouse, new Point(16, 16), "mycursor"));
        myButton.addActionListener((e)->{
            myChoose.dispose();
            timer.stop();
            new Thread(()->{
                new MyLoad(1);
            }).start();
        });
        label2.setBounds(600,420,200,100);
        label2.setFont(new Font("仿宋",Font.BOLD,30));
        jLabel = new JLabel();//倒计时显示
        jLabel.setBounds(100,20,300,300);
        jLabel.setFont(new Font("仿宋",Font.BOLD,100));
        this.add(jLabel,0);
        this.add(label2);
        this.add(myButton);
        this.add(label);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        timer = new Timer(1000,(e)->{
            forTimer();
        });
        timer.start();
        this.setVisible(true);
    }
    public void forTimer(){//为了在timer之外结束它所设置的方法，由于之前在npc处的守护线程也是用的lamda表达式，所以无法在内部关闭timer线程，后来也是用了提升作用域+函数这种方法
        if(num==-1) {//倒计时结束
            new MyFrame(1900,500,-950);
            this.dispose();//销毁该窗口
            timer.stop();//窗口销毁之后必须手动关闭timer，不然会一直占用资源
        }
        else jLabel.setText(""+num);//显示倒计时
        num--;
    }

}
